//
//  EFengChatListView.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/1/27.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengChatListView.h"
#import "UIImage+ImageWithColor.h"
#import "WZDepListCell.h"
#import "CUserSettingModel.h"
#import "CUserSettingMgr.h"
@interface EFengChatListView ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@end

@implementation EFengChatListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.image = [UIImage strechingWithImageName:@"depListBackGround"];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
    }
    return self;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = ClearColor;
        _tableView.scrollEnabled = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:_tableView];
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.chatListViewArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CUserSettingModel *settingModel = [[[CUserSettingMgr alloc]init] getUserSetting];
    WZDepListCell *cell = [WZDepListCell depListCellWithTableView:tableView];
    NSString *text = self.chatListViewArray[indexPath.row];
    if ([text isEqualToString:@"创建讨论组"]) {
        cell.imageView.image = [UIImage imageNamed:@"comments-0"];
        cell.imageView.hidden = NO;
    }
    if ([text isEqualToString:@"按视图显示"]) {
        if ([settingModel.yuLiuZiduan3 isEqualToString:@"按视图显示"]) {
            cell.imageView.image = [UIImage imageNamed:@"choseicon"];
        }
        else
        {
            cell.imageView.image = [UIImage imageNamed:@"fill"];

        }
    }
    if ([text isEqualToString:@"按部门显示"]) {
        if ([settingModel.yuLiuZiduan3 isEqualToString:@"按部门显示"]) {
            cell.imageView.image = [UIImage imageNamed:@"choseicon"];
        }
        else
        {
            cell.imageView.image = [UIImage imageNamed:@"fill"];

        }
    }
    cell.textLabel.textColor = RGBCOLORWITH16COLOR(0x323232);
    if (self.chatListViewArray.count - 1 == indexPath.row && self.chatListViewArray.count != 1) {
        cell.sepreateLine.hidden = YES;
        
    } else {
        cell.sepreateLine.hidden = NO;
    }
    cell.textLabel.text = text;
   
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.chatListDelegate respondsToSelector:@selector(eFengChatListDidSelectWithIndexPath:)]) {
        [self.chatListDelegate eFengChatListDidSelectWithIndexPath:indexPath];
    }
}

- (void)showChatListView
{
    self.frame = CGRectMake(HARDWARE_SCREEN_WIDTH - 150.0f - 7.0f, 0, 150.0f, 0);
    [UIView animateWithDuration:0.3f animations:^{
        CGRect rec = self.frame;
        rec.size.height = self.chatListViewArray.count * 44.0f + 5.0f;
        self.frame = rec;
        self.tableView.frame = CGRectMake(0, 5.0f, rec.size.width, rec.size.height- 5.0f);
    } completion:^(BOOL finished) {
        [self.tableView reloadData];
    }];
}

- (void)hieChatListView
{
    [UIView animateWithDuration:0.3f animations:^{
        CGRect rec = self.frame;
        rec.size.height = 0;
        self.frame = rec;
        self.tableView.frame = CGRectMake(0, 0, rec.size.width, rec.size.height);
    } completion:^(BOOL finished) {
        [self.tableView reloadData];
    }];
    
}

@end
